/*!
\copyright  Copyright (c) 2024 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      BT Class of Device Management.
*/

#include "class_of_device.h"
#include "bt_device_class.h"
#include <logging.h>

#ifdef OPTION_SET_CLASS_OF_DEVICE
#define CLASS_OF_DEVICE                     OPTION_SET_CLASS_OF_DEVICE
#else

#ifndef INCLUDE_MIRRORING
#define OPTION_CAPTURING_MAJOR_SERV_CLASS   CAPTURING_MAJOR_SERV_CLASS /* for A2DP SRC */
#else
#define OPTION_CAPTURING_MAJOR_SERV_CLASS   0
#endif

#if defined(INCLUDE_LE_AUDIO_UNICAST) || defined(INCLUDE_LE_AUDIO_BROADCAST)
#define OPTION_LE_AUDIO_MAJOR_SERV_CLASS    LE_AUDIO_MAJOR_SERV_CLASS
#else
#define OPTION_LE_AUDIO_MAJOR_SERV_CLASS    0
#endif

#define DEFAULT_SERVICE_CLASS               (AUDIO_MAJOR_SERV_CLASS | RENDER_MAJOR_SERV_CLASS | OPTION_CAPTURING_MAJOR_SERV_CLASS | OPTION_LE_AUDIO_MAJOR_SERV_CLASS)
#define DEFAULT_MAJOR_DEVICE_CLASS          (AV_MAJOR_DEVICE_CLASS)
#define DEFAULT_MINOR_DEVICE_CLASS          (HEADSET_MINOR_DEVICE_CLASS)

#define CLASS_OF_DEVICE                     (DEFAULT_SERVICE_CLASS | DEFAULT_MAJOR_DEVICE_CLASS | DEFAULT_MINOR_DEVICE_CLASS)
#endif

#define SERVICE_CLASS_MASK                  0xFFE000
#define MAJOR_DEVICE_CLASS_MASK             0x1F00
#define MINOR_DEVICE_CLASS_MASK             0x00FC

static uint32 class_of_device = CLASS_OF_DEVICE;

uint32 ClassOfDevice_GetCoD(void)
{
    return class_of_device;
}

uint32 ClassOfDevice_GetMinorDeviceClass(void)
{
    return (class_of_device & MINOR_DEVICE_CLASS_MASK);
}

uint32 ClassOfDevice_GetMajorDeviceClass(void)
{
    return (class_of_device & MAJOR_DEVICE_CLASS_MASK);
}

uint32 ClassOfDevice_GetServiceClass(void)
{
    return (class_of_device & SERVICE_CLASS_MASK);
}

void ClassOfDevice_SetCoD(uint32 new_class_of_device)
{
    class_of_device = new_class_of_device & (SERVICE_CLASS_MASK | MAJOR_DEVICE_CLASS_MASK | MINOR_DEVICE_CLASS_MASK);
    DEBUG_LOG("ClassOfDevice_SetCoD CoD=0x%x", class_of_device);
}